<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box p:nth-child(3) {
            color: red;
        }

        .box p:nth-of-type(2) {
            background-color: #ff0;
        }

        .box p:last-of-type {
            color: bisque;
        }

        /* ul li:nth-of-type(2n) {
            color: red;
        } */


        /* even 偶数  2n */
        ul li:nth-child(even) {
            color: blueviolet;
        }

        /* odd奇数  2n+1 */
        ul li:nth-child(odd) {
            color: aquamarine;
        }
    </style>
</head>

<body>

    <!-- 
        nth-child   第几个子元素
        nth-of-type  类型的第几个
     -->

    <div class="box">
        <p>1</p>
        <h2>2</h2>
        <p>3</p>
        <p>4</p>
    </div>


    <!-- 在列表中 nth-child 和 nth-of-type 没有区别 -->
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
    </ul>

</body>

</html>